<template>
  <el-form
    :model="ruleForm"
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm adduser"
  >
    <el-form-item label="名字" prop="name">
      <el-input v-model="ruleForm.name"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="gender">
      <el-input v-model="ruleForm.gender"></el-input>
    </el-form-item>
    <el-form-item label="邮箱" prop="email">
      <el-input v-model="ruleForm.email"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="phone">
      <el-input v-model="ruleForm.phone"></el-input>
    </el-form-item>
    <el-form-item label="入职日期" prop="date">
      <el-input v-model="ruleForm.date"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="adduser('ruleForm')">添加</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        gender: "",
        email: "",
        phone: "",
        date: ""
      },
      rules: {
        name: [{ required: true, message: "请输入名字", trigger: "blur" }],
        gender: [{ required: true, message: "请输入性别", trigger: "blur" }],
        email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
        phone: [{ required: true, message: "请选择手机号", trigger: "change" }],
        date: [{ required: true, message: "请输入入职日期", trigger: "blur" }]
      }
    };
  },
  methods: {
    adduser(str) {
      this.$refs[str].validate(valid => {
        if (valid) {
          this.$emit("addper", this.$refs[str].model);
        }
      });
    }
  }
};
</script>

<style lang="sass">
.adduser
    display: flex
    flex-direction: row
    flex-wrap: wrap
</style>